import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)




export default new Vuex.Store({
  state: {
    list:{},
    activeId:'',
    activePage:1,
    activeContent:'',
    listLoading:true,
    types:[
			{name:"美容",id:1},
			{name:"减肥",id:10},
			{name:"保健养生",id:15},
			{name:'时节',id:62},
			{name:'调养',id:82},
			{name:'肠胃消化',id:98},
			{name:'孕产哺乳',id:112},
			{name:'经期',id:147},
			{name:'女性',id:161},
			{name:'男性',id:218},
			{name:'呼吸道',id:166},
			{name:'口腔',id:202},
			{name:'肌肉骨骼',id:205},
			{name:'癌症',id:227},
			{name:'养颜',id:2},
			{name:'排毒',id:3},
			{name:'美白',id:4},
			{name:'祛痘',id:7},
			{name:'祛斑',id:6},
			{name:'润肤',id:8}
		]
  },
  mutations:{
  	DOWNLOAD_LIST(state,id){
  		let dUrl='http://apis.baidu.com/tngou/cook/list';
  		let rows=20;
  		let key='1f3deff0b665a8da11d3150555fafdd1';
  		let page=state.activePage;
  		dl(dUrl,id,page,rows,key);

  		function dl(dUrl,id,page,rows,key){
			Vue.http({
				method:'GET',
				url:dUrl,
				params:{'id':id,'page':page,'rows':rows},
				headers:{'apikey':key},
				_timeout:10000,
				onTimeout:(request)=>{
					console.log('timeout')
				}
			}).then((response)=>{
				let data=response.data.tngou;
				state.list[id]?state.list[id]=state.list[id].concat(data):Vue.set(state.list,id,data);
				state.activePage++;
				setTimeout(()=>{
					state.listLoading=false;
				},300)
			},(response)=>{console.log(response)}).catch((response)=>{console.log(response)})
		};
		
		
  	},
  	SEARCH(state){

  	},
  	ENTRY_DETAIL(state,id){
  		state.activeId=id;
  		state.activePage=1;
  		state.listLoading=true;
  	},
  	RESET_ACTIVEID(state,id){
  		state.activeId=id
  	},
  	DELETE_LIST(state,id){
  		state.list=[]
  	}
  }
})